'use strict';

const path = require('path');

const classRouter = require('./classRouter.js');
const studentRouter = require('./studentRouter.js');
const subjectRouter = require('./subjectRouter.js');
const mainRouter = require('./mainRouter.js');

const router = function(app){

	// 这里到时候可以写后台权限（判断是否有登录）
	app.get('*',function(req,res,next){
		//console.log(req.url.indexOf('/admin/main/imgCode'))
		if(req.url != '/admin/main/login' && req.url != '/admin/main/register' && req.url.search(/\/admin\/main\/imgCode/) === -1){
			// console.log(req.session.email);
			if(req.session.email==undefined){
				// 没有登录
				res.redirect('/admin/main/login');
			}
			next();
		}else{
			next();	
		}
	});

	//管理权限
	app.use('/admin/class',classRouter);
	app.use('/admin/student',studentRouter);
	app.use('/admin/subject',subjectRouter);
	app.use('/admin/main',mainRouter);

	// 配置根目录的访问，写http://localhost:8888/ 就可以访问到登录页
	app.use('/',function(req,res){
		// 跳转
		res.redirect('/admin/main/login');
	});
}

module.exports = router;

